home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / inputs / ulem.sty < prev    next >
Encoding:
Text File  |  1991-05-21  |  6.8 KB  |  168 lines

  1. %
  2. %  U L E M . S T Y
  3. %
  4. %  A style file to use underlining, rather than italics, for \em-phasis.
  5. %  It is most suitable for simple text such as {\em ibid.} or {\em \LaTeX:
  6. %  A Document Preparation System\/} that may need to be underlined in a 
  7. %  manuscript submitted for publication.  Only to be used when emphasis
  8. %  is delimited by braces.
  9. %
  10. %  So you want to do some underlining but still want to get italics with 
  11. %  \em?  Just enter the declaration \normalem before beginning your document
  12. %  and specify your underlining as \ULine{some text}.
  13. %
  14. %  More instructions after \endinput.
  15. %
  16. %  Copyright (c) 1989 by Donald Arseneau
  17. %
  18. %  These macros may be freely transmitted, reproduced, or modified for
  19. %  non-commercial purposes provided that this notice is left intact.
  20. %
  21. \def\ULem{\let\em\LA@em
  22.    \expandafter\UL@on\expandafter{\ifnum0=`}\fi}%% -> \UL@on{
  23.  
  24. \def\ULine{\bgroup\UL@on}
  25.  
  26. \let\LA@em\em
  27. \let\em\ULem
  28. \def\normalem{\let\em\LA@em}
  29. \newbox\UL@hyphenbox
  30. \newbox\UL@box
  31. \newcount\UL@spfactor
  32. \newcount\UL@penalty
  33. \newskip\UL@skip
  34. \newdimen\UL@lht
  35. \newdimen\UL@ldp
  36. %
  37. %  Could do this... 
  38. %  \UL@lht=-.8pt \UL@ldp=1.2pt  %  ...see note a few lines down.
  39.  
  40. \let\LA@space\ \let\LA@hskip\hskip
  41.  
  42. \def\UL@end*{\relax\relax}% something harmless unlikely to be found elsewhere
  43.  
  44. \def\UL@on#1{\leavevmode\everymath{\UL@hrest}\let\-\UL@dischyp 
  45.     \let\ \UL@space \let\hskip\UL@hskip
  46. %
  47. %   Set the depth of the underline.  For a different depth, the next line 
  48. %   should be changed; or eliminated so \UL@ldp and \UL@lht can be defined 
  49. %   just once as style parameters.
  50. %
  51.     \setbox\UL@box\hbox{(}\UL@ldp\dp\UL@box \UL@lht-\UL@ldp\advance\UL@lht.4\p@
  52. %
  53.     \setbox\UL@hyphenbox\hbox{\setbox\UL@box\hbox{-}\UL@putbox}%
  54.     \UL@word#1\global\UL@spfactor\spacefactor{} \UL@end* }
  55.  
  56. \let\UL@unegroup\@empty
  57.  
  58. \def\UL@start{\setbox\UL@box\hbox\bgroup\everyhbox{\UL@hrest}%
  59. %   the following are to cope with stops (\ ,\- etc) within extra braces
  60.     \let\UL@start\@empty \let\UL@putbox\@empty \let\UL@unegroup\bgroup
  61.     \kern-3sp\kern3sp} % kerns so I can test for beginning of list
  62.  
  63. \def\UL@stop{\global\UL@penalty\lastpenalty
  64.    \ifdim\lastkern=3sp \egroup % Nothing in hbox, 
  65.       \ifdim\wd\UL@box=\z@ % make doubly sure, and don't put on list
  66.       \else \UL@putbox \fi
  67.    \else 
  68.       \egroup \UL@putbox
  69.    \fi\UL@unegroup}
  70.  
  71. \def\UL@putbox{{\UL@skip\wd\UL@box \advance\UL@skip\UL@pixel
  72.    \vrule \@height\UL@lht \@depth\UL@ldp \@width\UL@skip
  73.    \kern-\UL@skip}\box\UL@box
  74.    \ifnum\UL@penalty=\z@ \else \penalty\UL@penalty \fi}
  75.  
  76. \def\UL@word#1 {\UL@start#1 \ifx\UL@end#1\egroup % must expand to nothing ...
  77.                               % outside the ifs for syntactical spaces to work
  78.       \unkern \unskip % remove extra leader
  79.       \spacefactor\UL@spfactor \let\UL@word\egroup 
  80.    \else % not finished
  81.       \ifmmode\else \ifdim\lastskip=\z@\else % this should allow syntactical 
  82.           \global\UL@skip\lastskip \unskip   %    ...spaces
  83.           \UL@stop \UL@leaders
  84.       \fi\fi
  85.    \fi \UL@word}
  86.  
  87. %  With interword leaders, give some overlap to avoid gaps caused by
  88. %  round-off errors in the printing program.  Needs \unkern \unskip 
  89. %  above.  This version assumes 300 dots per inch, but it still looks good 
  90. %  with higher resolution, and will still work down to ~150 dpi.  Change the
  91. %  value of \UL@pixel if necessary.
  92.  
  93. \newdimen\UL@pixel \UL@pixel=0.0033333truein
  94.  
  95. \def\UL@leaders{{\advance \UL@skip \UL@pixel
  96.    \leaders\hrule \@height\UL@lht \@depth\UL@ldp\LA@hskip\UL@skip
  97.    \kern-\UL@pixel}}
  98.  
  99. \def\UL@hskip{\afterassignment\UL@reskip \global\UL@skip}
  100.  
  101. \def\UL@reskip{\UL@stop \UL@leaders \UL@start}
  102.  
  103. \def\UL@hrest{\let\hskip\LA@hskip \let\ \LA@space \let\-\UL@dischyp}
  104.  
  105. \def\UL@space{\LA@space \global\UL@skip\lastskip \unskip \UL@reskip}
  106.  
  107. \def\UL@dischyp{\penalty\z@ % zero penalty => no break (see \UL@stop)
  108.                \UL@stop \discretionary{\copy\UL@hyphenbox}{}{}\UL@start}
  109. \endinput
  110. %
  111. %  ULEM is far from an ideal replacement for \em, but it does allow line 
  112. %  breaks, and even primitive hyphenation, within the underlined text.  
  113. %  Every word is set in an underlined box, so normally it cannot be 
  114. %  hyphenated, but explicit discretionary hyphens (\-) can be used to 
  115. %  allow hyphenation.  Since spaces are used to delimit words, there may 
  116. %  be some difficulty with syntactical spaces (e.g. 2.3_pt). Some effort 
  117. %  is made to handle spaces, but if that fails, you might solve the problem 
  118. %  by enclosing the offending command in braces...
  119. %  
  120. %  One important incompatability is with grouping: EVERYTHING IN BRACES 
  121. %  IS TREATED LIKE AN MBOX.  Thus, braces will suppress stretching and 
  122. %  linebreaks in the text they enclose.  Moreover, the specially-taken-
  123. %  care-of commands \-, \ , and \hspace (\hskip) often fail if they appear 
  124. %  inside extra braces.  They succeed only if the enclosing braces are
  125. %  preceded and followed by spaces, but then they have another undesireable 
  126. %  effect: they end the group and start a new one!  Thus, the only braces 
  127. %  you should use are those delimiting parameters to commands, or those 
  128. %  with simple text inside.  Syntactical spaces inside braces never cause 
  129. %  a problem, nor do spaces in math mode.
  130. %  
  131. %  Text produced by expansion of a command word is boxed too, but the 
  132. %  commands \  and \- still work; just as for braces surrounded by space:  
  133. %      \newcommand\iff{if and only if} {\em \iff} 
  134. %  does not allow any stretching or linebreaking between words, but
  135. %      \newcommand\iff{if\ and\ only\ if} {\em \iff}
  136. %  allows stretching and linebreaking.
  137. %
  138. %  Nested \em commands produce underlined italics, but heed the warnings 
  139. %  about braces above.  Since nested \em-phasis normally switches back to
  140. %  roman type, this is another incompatability.  To get italics without 
  141. %  underlining, use \it.
  142. %
  143. %  HERE IS A DIFFICULT EXAMPLE.
  144. %
  145. %  \documentstyle[12pt,ulem]{article}  % or [ulem]
  146. %  \setlength\textwidth{3.3in}
  147. %  \begin{document}
  148. %  No, I did {\em not} act in the movie {\em {\em The} % <<<< Nested
  149. %  {\em Persecu\-\em tion}  {\em and} {\em  Assassination} {\em of} 
  150. %  {\em Jean-Paul} {\em Marat}, as per\-formed by the Inmates
  151. %  of the Asylum of Charenton under the Direc\-tion of the 
  152. %  Marquis de~Sade!} But I {\em did} see it.
  153. %  \end{document}
  154. %
  155. %  In the nested emphasis, \em is given for each word so that the interword
  156. %  spaces can be outside the braces.  Otherwise, there would be no stretch 
  157. %  to the line.  Note that the discretionary hyphen (\-) in Persecution
  158. %  cancelled the inner \em, thus \-\em was needed, but the hyphen in Direction
  159. %  was just fine because it was not in nested braces.  Whew!
  160. %  This example illustrates that ULEM is not made for nested emphasis!
  161. %  Nevertheless, it works great for simple things.
  162. %
  163. %  Send problem reports to asnd@triumfcl.bitnet or Arseneau@mtsg.ubc.ca
  164. %
  165. %  Test transmission:
  166. %  brackets: round, square, curly, angle:   () [] {} <>
  167. %  backslash, slash, vertical, hat, tilde:   \ / | ^ ~
  168.